package com.ruoyi.web.gj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.gj.domain.WarningInfo;
import com.ruoyi.web.gj.service.IWarningInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警数据Controller
 *
 * @author ruoyi
 * @date 2025-09-19
 */
@RestController
@RequestMapping("/system/warning")
public class WarningInfoController extends BaseController
{
    @Autowired
    private IWarningInfoService warningInfoService;

    /**
     * 查询告警数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:warning:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarningInfo warningInfo)
    {
        startPage();
        List<WarningInfo> list = warningInfoService.selectWarningInfoList(warningInfo);
        return getDataTable(list);
    }

    /**
     * 导出告警数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:warning:export')")
    @Log(title = "告警数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarningInfo warningInfo)
    {
        List<WarningInfo> list = warningInfoService.selectWarningInfoList(warningInfo);
        ExcelUtil<WarningInfo> util = new ExcelUtil<WarningInfo>(WarningInfo.class);
        util.exportExcel(response, list, "告警数据数据");
    }

    /**
     * 获取告警数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:warning:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(warningInfoService.selectWarningInfoById(id));
    }

    /**
     * 新增告警数据
     */
    @PreAuthorize("@ss.hasPermi('system:warning:add')")
    @Log(title = "告警数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarningInfo warningInfo)
    {
        return toAjax(warningInfoService.insertWarningInfo(warningInfo));
    }

    /**
     * 修改告警数据
     */
    @PreAuthorize("@ss.hasPermi('system:warning:edit')")
    @Log(title = "告警数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarningInfo warningInfo)
    {
        return toAjax(warningInfoService.updateWarningInfo(warningInfo));
    }

    /**
     * 删除告警数据
     */
    @PreAuthorize("@ss.hasPermi('system:warning:remove')")
    @Log(title = "告警数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(warningInfoService.deleteWarningInfoByIds(ids));
    }
}
